import axios from "axios";
import {Toast} from "vant";
var services=axios.create({
	//baseURL:"https://m.maizuo.com" //所有请求都会带上baseURL;
	baseURL:"/mz",
	timeout:3000,//设置超时的时间
	headers:{
		"Content-Type": "application/json",
		// "X-Client-Info": `{"a":"3000","ch":"1002","v":"5.0.4","e":"15882364202555505542707","bc":"110100"}`
	}
});
// axios.defaults.baseURL="/mz";
//  //把每一次请求都要带的请求头，设置一下
// axios.defaults.headers={
// 	"Content-Type": "application/json",
// 	"X-Client-Info": `{"a":"3000","ch":"1002","v":"5.0.4","e":"15882364202555505542707","bc":"110100"}`
// };
// axios.defaults.timeout=3000;

//请求拦截器  这个拦截器会在发请求时自动执行
var toast=null;
services.interceptors.request.use((config)=>{
	// console.log(config);
	// console.log("请求被拦截了");
	toast=Toast.loading({
		duration:0,//显示的时间 0 持续显示
		message:"加载中。。。",
		forbidClick:false,//禁止点击
	});
	config.headers["X-Client-Info"]=`{"a":"3000","ch":"1002","v":"5.0.4","e":"15882362692559800509922","bc":"110100"}`
	return config;
})

//响应拦截器 这个拦截器会在数据返回时执行
services.interceptors.response.use((res)=>{
	toast.clear();
	return res.data;
})

export default services;